<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/3/15
 * Time: 10:57
 */

namespace App\Http\Logics\MiniProgramAdmin;


use App\SystemNotify;
use App\Http\Logics\BaseLogic;
class SystemNotifyLogic extends BaseLogic
{
    public static function createSystemNotify($data)
    {
        $system_notify = new SystemNotify();
        $system_notify->title = $data['title'];
        if (!$system_notify->save()){
            return self::response(self::OBJECT_SAVE_FAIL);
        }
        return self::response(self::SUCCESS, $system_notify->id);
    }
    public static function getSystemNotifyList($data)
    {
        $query = SystemNotify::where(function($query){
        })->orderBy('created_at', 'desc');
        $system_notify = $data['limit'] ? $query->paginate($data['limit']) : $query->get();
        if (empty($system_notify)){
            return self::response(self::CONTENT_IS_EMPTY);
        }
        return self::response(self::SUCCESS, $system_notify);
    }
    public static function detail($data)
    {
        $system_notify = SystemNotify::with(['systemNotifyContent'])->find($data['system_notify_id']);
        if (empty($system_notify)){
            return self::response(self::CONTENT_IS_EMPTY);
        }
        return self::response(self::SUCCESS, $system_notify);
    }

    public static function delete($data)
    {
        $system_notify = SystemNotify::with(['systemNotifyContent'])->find($data['system_notify_id']);
        if (!$system_notify->delete()){
            return self::response(self::OBJECT_DELETE_FAILD);
        }
        return self::response(self::SUCCESS);
    }
}